//
//  ViewController.m
//  SortedArrayiOS
//
//  Created by  ZhuHong on 2017/2/18.
//  Copyright © 2017年 CoderHG. All rights reserved.
//

#import "ViewController.h"
#import "SortedArrayMode.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 创建一堆的测试mode数据
    SortedArrayMode* mode0 = [SortedArrayMode modeWithName:@"name3" address:@"address" phone:@"phone"];
    SortedArrayMode* mode1 = [SortedArrayMode modeWithName:@"name4" address:@"address" phone:@"phone2"];
    SortedArrayMode* mode2 = [SortedArrayMode modeWithName:@"name4" address:@"address" phone:@"phone1"];
    SortedArrayMode* mode3 = [SortedArrayMode modeWithName:@"name1" address:@"address" phone:@"phone"];
    SortedArrayMode* mode4 = [SortedArrayMode modeWithName:@"name2" address:@"address2" phone:@"phone"];
    SortedArrayMode* mode5 = [SortedArrayMode modeWithName:@"name5" address:@"address" phone:@"phone3"];
    SortedArrayMode* mode6 = [SortedArrayMode modeWithName:@"name2" address:@"address1" phone:@"phone"];
    SortedArrayMode* mode7 = [SortedArrayMode modeWithName:@"name7" address:@"address" phone:@"phone"];
    SortedArrayMode* mode8 = [SortedArrayMode modeWithName:@"name5" address:@"address" phone:@"phone4"];
    
    // 放到数组中
    NSArray* modeArr = @[mode0, mode1, mode2, mode3, mode4, mode5, mode6, mode7, mode8];
    
    
    NSLog(@"排序前 \n%@", modeArr);
    
    // 排序的优先级是 name  address  phone
    NSSortDescriptor* nameDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
    NSSortDescriptor* addressDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"address" ascending:YES];
    NSSortDescriptor* phoneDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"phone" ascending:YES];
    
    NSArray* descriptorArr = @[nameDescriptor, addressDescriptor, phoneDescriptor];
    
    NSArray* otherArr = [modeArr sortedArrayUsingDescriptors:descriptorArr];
    
    NSLog(@"排序后 \n%@", otherArr);
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
